import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { MsgTypeImpl } from "../../manager/MsgTypeImpl";
import { Cache } from "../../cache/Cache";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { ChatItemData } from "../chat/chatViewData/ChatItemData";
import { ChatMessageWorking } from "../chat/chatViewData/ChatMessageWorking";
import { ChatArea } from "../chat/ChatArea";
import { ChatCellData } from "../chat/chatViewData/ChatCellData";
import { ChatItem } from "../chat/chatPanel/ChatItem";
import { LoadSettings } from "../../../common/global/LoadSettings";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { SWFInfo } from "../../../../com/gengine/resource/info/SWFInfo";
import { TweenMax } from "../../../../com/greensock/TweenMax";
type int = number;
//class SpeakerItem
    
    export  class SpeakerItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._maskSp = new Object /* flash.display.Sprite */();
            this._maskSp.graphics.beginFill(16777215, 0.1);
            this._maskSp.graphics.drawRect(0, 0, 300, 102);
            this._maskSp.graphics.endFill();
            this._maskSp.y = -10;
            this._maskSp.mouseChildren = false;
            this._maskSp.mouseEnabled = false;
            this.addChild(this._maskSp);
            this._itemSprite = new Object /* flash.display.Sprite */();
            this._itemSprite.x = 0;
            this._itemSprite.mouseEnabled = false;
            this._itemSprite.mask = this._maskSp;
            this.addChild(this._itemSprite);
            mouseChildren = true;
            mouseEnabled = false;
            return;
        }

        public init(arg1: PlayerMiniInfo, arg2: string, arg3: MsgTypeImpl): void
        {
            var loc4=0;
            this._level = Cache.instance.role.entityInfo.level;
            this._delay = arg3.delay;
            var loc1=arg3.color;
            var loc2;
            (loc2 = ObjectPool.getObject(ChatItemData)).type = ChatMessageWorking.getChatTypeByAreaName(ChatArea.Speaker);
            var loc3=new Vector.<ChatCellData>();
            if (arg1.isVIP) 
            {
                loc4 = 3;
            }
            else 
            {
                loc4 = 1;
            }
            loc3 = (loc3 = loc3.concat(ChatMessageWorking.getPlayerCellData(arg1))).concat(ChatMessageWorking.getCellDataByContent(arg2, parseInt(loc1), true, 12, loc4));
            loc2.cellVector = loc3;
            this._chatItem = ObjectPool.getObject(ChatItem);
            this._chatItem.init(loc2.getContentElement(), 280);
            this._chatItem.x = 7;
            this._chatItem.y = 22;
            this._itemSprite.addChild(this._chatItem);
            if (this._level > LoadSettings.Effectslevel) 
            {
                if (this._mc != null) 
                {
                    this._itemSprite.addChildAt(this._mc, 0);
                    this._mc.play();
                }
                else 
                {
                    LoaderManager.instance.load("speakerflash.swf", this.onLoaded);
                }
            }
            return;
        }

        /* internal  */onLoaded(arg1: SWFInfo): void
        {
            this._mc = arg1.clip;
            this._mc.x = -10;
            this._mc.y = 0;
            this._itemSprite.addChildAt(this._mc, 0);
            this._mc.play();
            this._mc.mouseEnabled = false;
            this._mc.mouseChildren = false;
            return;
        }

        /* internal  */onInEnd(): void
        {
            this._timerKey = flash.utils.setTimeout(this.timerOutHandler, this._delay);
            return;
        }

        /* internal  */onOutEnd(): void
        {
            if (this._endFun != null) 
            {
                this._endFun.call(this, this);
            }
            return;
        }

        /* internal  */timerOutHandler(): void
        {
            this._outTween = TweenMax.to(this._itemSprite, 0.1, {"alpha": 0, "onComplete": this.onOutEnd});
            return;
        }

        public updateData(arg1: Function, arg2: Boolean=true): void
        {
            this._endFun = arg1;
            if (arg2) 
            {
                this._itemSprite.alpha = 0;
                this._itemSprite.y = 20;
                this._inTween = TweenMax.to(this._itemSprite, 0.1, {"alpha": 1, "y": 0, "onComplete": this.onInEnd});
            }
            else 
            {
                this._itemSprite.alpha = 1;
                this._itemSprite.y = 0;
                this.onInEnd();
            }
            return;
        }

        public killInEase(): void
        {
            if (this._inTween && this._inTween.active) 
            {
                this._itemSprite.y = 0;
                this._itemSprite.alpha = 1;
                this._inTween.kill();
                this.onInEnd();
            }
            return;
        }

        public dispose(): void
        {
            this._endFun = null;
            flash.utils.clearTimeout(this._timerKey);
            if (this._inTween && this._inTween.active) 
            {
                this._inTween.kill();
            }
            else if (this._outTween && this._outTween.active) 
            {
                this._outTween.kill();
            }
            if (this._itemSprite) 
            {
                this._itemSprite.alpha = 1;
                this._itemSprite.y = 0;
                if (this._chatItem && this._chatItem.parent) 
                {
                    this._itemSprite.removeChild(this._chatItem);
                }
                if (this._mc) 
                {
                    if (this._mc.parent) 
                    {
                        this._itemSprite.removeChild(this._mc);
                    }
                    this._mc.stop();
                }
            }
            return;
        }

        public /* override */ get height(): number
        {
            return this._itemSprite.height;
        }

        public /* override */ get width(): number
        {
            return this._itemSprite.width;
        }

        /* internal */ /* var */_maskSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_itemSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_chatItem: ChatItem;

        /* internal */ /* var */_endFun: Function;

        /* internal */ /* var */_inTween: TweenMax;

        /* internal */ /* var */_outTween: TweenMax;

        /* internal */ /* var */_timerKey: uint;

        /* internal */ /* var */_delay: number;

        /* internal */ /* var */_level: int;

        /* internal */ /* var */_mc: Object /* flash.display.MovieClip */;
    }
